package com.poker.task;

import com.poker.consts.Code;
import com.poker.entity.Activity;
import com.poker.service.ActivityService;
import com.poker.util.Misc;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by lxs.
 * 2019/3/28 5:10 PM
 */
@Component
public class ActivityTask {

    @Resource
    private ActivityService activityService;

    @Scheduled(cron = "0 0/5 * ? * ?")
    public void reportCurrentTime() {

        // 未开始的活动，状态更改为1
        List<Activity> actSign = activityService.findActSign();
        for (Activity act : actSign) {
            if (Misc.isEmpty(act.getStatus()) || act.getStatus() != 1) {
                act.setStatus(Integer.valueOf(Code.ActivityStatus.SIGNING));
                activityService.updateStatus(act);
            }
        }

        // 进行中的活动，状态不为2的更改为2
        List<Activity> actIng = activityService.findActIng();
        for (Activity act : actIng) {
            if (Misc.isEmpty(act.getStatus()) || act.getStatus() != 2) {
                act.setStatus(Integer.valueOf(Code.ActivityStatus.HAVING));
                activityService.updateStatus(act);
            }
        }

        // 已结束的活动，状态更改为3
        List<Activity> actEnd = activityService.findActEnd();
        for (Activity act : actEnd) {
            if (Misc.isEmpty(act.getStatus()) || act.getStatus() != 3) {
                act.setStatus(Integer.valueOf(Code.ActivityStatus.END));
                activityService.updateStatus(act);
            }
        }

    }

}
